﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
using System.Text;
using System.Linq;
using System.Web;
using System.Reflection;
using System.IO;
using System.Web.UI.WebControls;
using System.Data;

namespace LIB
{
    public class StringUtility
    {
        public static string RemoveInvalidHTMLTags(string HTMLContent, string[] ValidHTMLTags)
        {
            string retStr = string.Empty;
            retStr = HTMLContent;

            if (ValidHTMLTags != null)
            {
                foreach (Match m in Regex.Matches(HTMLContent, "</?(?<tagname>[a-z][a-z0-9]*)[^<>]*>", RegexOptions.IgnoreCase))
                {
                    string tagName = m.Groups["tagname"].Value;

                    if (!ValidHTMLTags.Contains(tagName))
                    {
                        retStr = retStr.Replace(m.Value, string.Empty);
                    }

                }
            }
            else
            {
                retStr = Regex.Replace(HTMLContent, "</?(?<tagname>[a-z][a-z0-9]*)[^<>]*>", string.Empty);
            }

            return retStr;
        }
        public static string OptimiseHtml(string strInput)
        {

            if (strInput.Length > 400)
            {
                string temp = strInput.Substring(0, 400);
                temp = temp.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace("\n\r", "").Replace("\r\n", "").Replace("\"", "\"\"");
                strInput = temp.Substring(0, temp.LastIndexOf(" ")) + "...";
            }
            else
            {
                strInput = strInput.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace("\n\r", "").Replace("\r\n", "").Replace("\"", "\"\"");
            }
            return strInput;

        }
        public static string SafeHtmlToText(string s)
        {
            string tmp = s;
            tmp = tmp.Replace(((char)13).ToString(), string.Empty);
            tmp = tmp.Replace(((char)10).ToString(), string.Empty);
            tmp = CaseInsensitiveReplace(tmp, "<br>", ((char)13).ToString());

            bool isTag = false;
            string retVal = string.Empty;
            for (int i = 0; i < tmp.Length; i++)
            {
                switch (tmp[i])
                {
                    case '<':
                        isTag = true;
                        break;
                    case '>':
                        isTag = false;
                        break;
                    default:
                        if (!isTag)
                            retVal += tmp[i];
                        break;
                }
            }
            return HttpUtility.HtmlDecode(retVal);
        }
        public static string CaseInsensitiveReplace(string s, string sold, string snew)
        {
            string retVal, searchStr, patt, newStr;
            int offset;

            searchStr = s.ToLower();
            patt = sold.ToLower();

            newStr = s;
            retVal = string.Empty;

            while (searchStr != string.Empty)
            {
                offset = searchStr.IndexOf(patt);
                if (offset == -1)
                {
                    retVal += newStr;
                    break;
                }

                retVal += newStr.Substring(0, offset) + snew;
                newStr = newStr.Remove(0, offset + sold.Length);
                searchStr = searchStr.Remove(0, offset + patt.Length);
            }
            return retVal;
        }
        public static string OptimiseContent(string source)
        {
            try
            {
                string result;

                // Remove HTML Development formatting
                result = source.Replace("\r", " ").Replace("\n", "").Replace("\t", "").Replace("\n\r", "").Replace("\r\n", "").Replace("\"", "\"\""); // Replace line breaks with space because browsers inserts space
                result = result.Replace("<strong>", "").Replace("</strong>", "").Replace("<b>", "").Replace("</b>", "");
                result = Regex.Replace(result, @"( )*font([^>])*", "", RegexOptions.IgnoreCase);
                result = result.Replace("</font>", "");
                result = Regex.Replace(result, "( )*style=\\\"font([^>])*", "", RegexOptions.IgnoreCase);

                result = Regex.Replace(result, @"<p>", "", RegexOptions.IgnoreCase);
                result = result.Replace("</p>", "");

                result = result.Replace("<br>", "");

                result = Regex.Replace(result, @"<span>", "", RegexOptions.IgnoreCase);
                result = result.Replace("</span>", "");

                result = Regex.Replace(result, @"<div>", "", RegexOptions.IgnoreCase);
                result = result.Replace("</div>", "");

                return result;

            }
            catch
            {
                return source;
            }
        }
        public static string StripHTML(string source)
        {
            try
            {
                string result;

                // Remove HTML Development formatting
                result = source.Replace("\r", " "); // Replace line breaks with space because browsers inserts space
                result = result.Replace("\n", " "); // Replace line breaks with space because browsers inserts space
                result = result.Replace("\t", string.Empty); // Remove step-formatting
                result = Regex.Replace(result, @"( )+", " "); // Remove repeating speces becuase browsers ignore them

                // Remove the header (prepare first by clearing attributes)
                result = Regex.Replace(result, @"<( )*head([^>])*>", "<head>", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, @"(<( )*(/)( )*head( )*>)", "</head>", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, "(<head>).*(</head>)", string.Empty, RegexOptions.IgnoreCase);

                // remove all scripts (prepare first by clearing attributes)
                result = Regex.Replace(result, @"<( )*script([^>])*>", "<script>", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, @"(<( )*(/)( )*script( )*>)", "</script>", RegexOptions.IgnoreCase);
                //result = System.Text.RegularExpressions.Regex.Replace(result, @"(<script>)([^(<script>\.</script>)])*(</script>)",string.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                result = Regex.Replace(result, @"(<script>).*(</script>)", string.Empty, RegexOptions.IgnoreCase);

                // remove all styles (prepare first by clearing attributes)
                result = Regex.Replace(result, @"<( )*style([^>])*>", "<style>", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, @"(<( )*(/)( )*style( )*>)", "</style>", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, "(<style>).*(</style>)", string.Empty, RegexOptions.IgnoreCase);

                // insert tabs in spaces of <td> tags
                result = Regex.Replace(result, @"<( )*td([^>])*>", "\t", RegexOptions.IgnoreCase);

                // insert line breaks in places of <BR> and <LI> tags
                result = Regex.Replace(result, @"<( )*br( )*>", "\r", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, @"<( )*li( )*>", "\r", RegexOptions.IgnoreCase);

                // insert line paragraphs (double line breaks) in place if <P>, <DIV> and <TR> tags
                result = Regex.Replace(result, @"<( )*div([^>])*>", "\r\r", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, @"<( )*tr([^>])*>", "\r\r", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, @"<( )*p([^>])*>", "\r\r", RegexOptions.IgnoreCase);

                // Remove remaining tags like <a>, links, images, comments etc - anything thats enclosed inside < >
                result = Regex.Replace(result, @"<[^>]*>", string.Empty, RegexOptions.IgnoreCase);

                // replace special characters:
                result = Regex.Replace(result, @"&nbsp;", " ", RegexOptions.IgnoreCase);

                result = Regex.Replace(result, @"&bull;", " * ", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, @"&lsaquo;", "<", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, @"&rsaquo;", ">", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, @"&trade;", "(tm)", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, @"&frasl;", "/", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, @"&lt;", "<", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, @"&gt;", ">", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, @"&copy;", "(c)", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, @"&reg;", "(r)", RegexOptions.IgnoreCase);
                // Remove all others. More can be added, see http://hotwired.lycos.com/webmonkey/reference/special_characters/
                result = Regex.Replace(result, @"&(.{2,6});", string.Empty, RegexOptions.IgnoreCase);

                // for testng
                //System.Text.RegularExpressions.Regex.Replace(result, this.txtRegex.Text,string.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase);

                // make line breaking consistent
                result = result.Replace("\n", "\r");

                // Remove extra line breaks and tabs: replace over 2 breaks with 2 and over 4 tabs with 4. 
                // Prepare first to remove any whitespaces inbetween the escaped characters and remove redundant tabs inbetween linebreaks
                result = Regex.Replace(result, "(\r)( )+(\r)", "\r\r", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, "(\t)( )+(\t)", "\t\t", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, "(\t)( )+(\r)", "\t\r", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, "(\r)( )+(\t)", "\r\t", RegexOptions.IgnoreCase);
                result = Regex.Replace(result, "(\r)(\t)+(\r)", "\r\r", RegexOptions.IgnoreCase); // Remove redundant tabs
                result = Regex.Replace(result, "(\r)(\t)+", "\r\t", RegexOptions.IgnoreCase); // Remove multible tabs followind a linebreak with just one tab
                string breaks = "\r\r\r"; // Initial replacement target string for linebreaks
                string tabs = "\t\t\t\t\t"; // Initial replacement target string for tabs
                for (int index = 0; index < result.Length; index++)
                {
                    result = result.Replace(breaks, "\r\r");
                    result = result.Replace(tabs, "\t\t\t\t");
                    breaks = breaks + "\r";
                    tabs = tabs + "\t";
                }

                // Thats it.
                return result;

            }
            catch
            {
                //MessageBox.Show("Error");
                return source;
            }

        }
        public static string RemoveNewLines(string input, bool addSpace)
        {
            string replace = string.Empty;
            if (addSpace)
                replace = " ";

            string pattern = @"[\r|\n]";
            Regex regEx = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline);

            return regEx.Replace(input, replace);
        }
        public static string RemoveNewLines(string input)
        {
            return RemoveNewLines(input, false);
        }
        public static string Alert(string strAlert)
        {
            return "return confirm('" + strAlert + "')";
        }

        public static string GetSubstring(string Content, int leng)
        {
            if (Content.Length > leng)
            {
                string temp = Content.Substring(0, leng);
                temp = temp.Replace("\r", "").Replace("\n", "").Replace("\t", "");
                if (temp.LastIndexOf(" ") != -1)
                {
                    Content = temp.Substring(0, temp.LastIndexOf(" ")) + "...";
                }
                else
                {
                    Content = temp.Substring(0, leng) + "...";
                }                
            }
            else
            {
                Content = Content.Replace("\r", "").Replace("\n", "").Replace("\t", "");                
            }
            return Content;
        }
        public static string UpdateQueryStringItem(HttpRequest httpRequest, string queryStringKey, string newQueryStringValue)
        {
            StringBuilder NewURL = new StringBuilder();

            NewURL.Append(httpRequest.RawUrl);

            if (httpRequest.QueryString[queryStringKey] != null)
            {
                string OrignalSet = string.Format("{0}={1}", queryStringKey, httpRequest.QueryString[queryStringKey]);
                string NewSet = string.Format("{0}={1}", queryStringKey, newQueryStringValue);
                NewURL.Replace(OrignalSet, NewSet);
            }
            else if (httpRequest.QueryString.Count == 0)
            {
                NewURL.AppendFormat("?{0}={1}", queryStringKey, newQueryStringValue);
            }
            else
            {
                NewURL.AppendFormat("&{0}={1}", queryStringKey, newQueryStringValue);
            }

            return NewURL.ToString();
        }

        public static string UpdateQueryStringItem(HttpRequest httpRequest, string[] queryStringKeys, string[] newQueryStringValues)
        {
            StringBuilder NewURL = new StringBuilder();

            NewURL.Append(httpRequest.RawUrl.Replace("%20", " "));
            bool check = true;
            for (int i = 0; i < queryStringKeys.GetLength(0); i++)
            {
                string queryStringKey = queryStringKeys[i];
                string newQueryStringValue = newQueryStringValues[i];
                if (httpRequest.QueryString[queryStringKey] != null)
                {
                    string OrignalSet = string.Format("{0}={1}", queryStringKey, httpRequest.QueryString[queryStringKey]);
                    string NewSet = string.Format("{0}={1}", queryStringKey, newQueryStringValue);
                    NewURL.Replace(OrignalSet, NewSet);
                }
                else if (httpRequest.QueryString.Count == 0)
                {
                    if (newQueryStringValue != "" && newQueryStringValue != null)
                    {
                        if (check)
                        {
                            NewURL.AppendFormat("?{0}={1}", queryStringKey, newQueryStringValue);
                            check = false;
                        }
                        else NewURL.AppendFormat("&{0}={1}", queryStringKey, newQueryStringValue);
                    }
                }
                else if (newQueryStringValue != "" && newQueryStringValue != null) NewURL.AppendFormat("&{0}={1}", queryStringKey, newQueryStringValue);
            }

            return NewURL.ToString();
        }

        public static void FillTreeData(ListItemCollection lst, DataTable dtCommands, string fieldKey, string fieldName, string fieldParentID, string sortBy)
        {
            lst.Clear();
            DataRow[] drRoots = dtCommands.Select(fieldParentID + "  = " + 0, sortBy);
            foreach (DataRow row in drRoots)
            {
                ListItem item = new ListItem();
                item.Value = row[fieldKey].ToString();
                item.Text = row[fieldName].ToString();
                item.Attributes.Add("Level", "0");
                lst.Add(item);
                LoadCmdItem(lst, item, dtCommands, fieldKey, fieldName, fieldParentID, sortBy);
            }
        }

        private static void LoadCmdItem(ListItemCollection lst, ListItem curItem, DataTable dtCommands, string fieldKey, string fieldName, string fieldParentID, string sortBy)
        {
            int level = Convert.ToInt32(curItem.Attributes["Level"]);
            level += 1;
            int curID = Convert.ToInt32(curItem.Value);
            DataRow[] drChilds = dtCommands.Select(fieldParentID + " = " + curID);
            foreach (DataRow row in drChilds)
            {
                ListItem childItem = new ListItem();
                childItem.Text = StringIndent(level) + row[fieldName].ToString();
                childItem.Value = row[fieldKey].ToString();
                childItem.Attributes.Add("Level", level.ToString());
                lst.Add(childItem);
                LoadCmdItem(lst, childItem, dtCommands, fieldKey, fieldName, fieldParentID, sortBy);
            }
        }

        public static void FillIndex(DropDownList dropIndex, int min, int max, int selected)
        {
            dropIndex.Items.Clear();
            for (int i = min; i <= max; i++)
            {
                ListItem item = new ListItem(i.ToString(), i.ToString());
                if (i == selected) item.Selected = true;
                else item.Selected = false;
                dropIndex.Items.Add(item);
            }
        }

        public static void FillIndex(DropDownList dropIndex, int max, int selected)
        {
            dropIndex.Items.Clear();
            for (int i = 0; i <= max; i++)
            {
                ListItem item = new ListItem(i.ToString(), i.ToString());
                if (i == selected) item.Selected = true;
                else item.Selected = false;
                dropIndex.Items.Add(item);
            }
        }


        public static void SelectItemFromList(ListControl list, string selectedValue)
        {
            list.SelectedIndex = -1;
            ListItem item = list.Items.FindByValue(selectedValue);
            if (item != null)
                item.Selected = true;
        }
        public static void SelectItemFromList(ListControl list, string[] selectedValues)
        {
            list.SelectedIndex = -1;
            for (int i = 0; i < selectedValues.Length; i++)
            {
                string selectedValue = selectedValues[i];
                ListItem item = list.Items.FindByValue(selectedValue);
                if (item != null)
                    item.Selected = true;
            }
        }
        /// <summary>
        /// Sets the selected.
        /// </summary>
        /// <param name="lstItems">The LST items.</param>
        /// <param name="selectedValue">The selected value.</param>
        public static void SetSelected(ListItemCollection lstItems, string selectedValue)
        {
            ListItem item = lstItems.FindByValue(selectedValue);
            if (item != null) item.Selected = true;
        }

        /// <summary>
        /// Sets the selected.
        /// </summary>
        /// <param name="dropList">The drop list.</param>
        /// <param name="selectedValue">The selected value.</param>
        public static void SetSelected(DropDownList dropList, string selectedValue)
        {
            dropList.SelectedIndex = -1;
            SetSelected(dropList.Items, selectedValue);
        }

        /// <summary>
        /// Sets the selected.
        /// </summary>
        /// <param name="list">The list.</param>
        /// <param name="selectedValue">The selected value.</param>
        public static void SetSelected(ListBox list, string selectedValue)
        {
            list.SelectedIndex = -1;
            SetSelected(list.Items, selectedValue);
        }

        /// <summary>
        /// Sets the selected.
        /// </summary>
        /// <param name="rdoList">The rdo list.</param>
        /// <param name="selectedValue">The selected value.</param>
        public static void SetSelected(RadioButtonList rdoList, string selectedValue)
        {
            rdoList.SelectedIndex = -1;
            SetSelected(rdoList.Items, selectedValue);
        }

        public static string StringIndent(int level)
        {
            string retVal = string.Empty;
            for (int i = 0; i < level; i++)
                retVal += ".....";
            return retVal;
        }
    }

    public class UnicodeUtility
    {
        private const string uniChars =
           "àáảãạâầấẩẫậăằắẳẵặèéẻẽẹêềếểễệđìíỉĩịòóỏõọôồốổỗộơờớởỡợùúủũụưừứửữựỳýỷỹỵÀÁẢÃẠÂẦẤẨẪẬĂẰẮẲẴẶÈÉẺẼẸÊỀẾỂỄỆĐÌÍỈĨỊÒÓỎÕỌÔỒỐỔỖỘƠỜỚỞỠỢÙÚỦŨỤƯỪỨỬỮỰỲÝỶỸỴÂĂĐÔƠƯ";

        private const string KoDauChars =
            "aaaaaaaaaaaaaaaaaeeeeeeeeeeediiiiiooooooooooooooooouuuuuuuuuuuyyyyyAAAAAAAAAAAAAAAAAEEEEEEEEEEEDIIIOOOOOOOOOOOOOOOOOOOUUUUUUUUUUUYYYYYAADOOU";

        public static int UnicodeToUTF8(byte[] dest, int maxDestBytes, string source, int sourceChars)
        {
            int i, count;
            int c, result;

            result = 0;
            if ((source != null && source.Length == 0))
                return result;
            count = 0;
            i = 0;
            if (dest != null)
            {
                while ((i < sourceChars) && (count < maxDestBytes))
                {
                    c = (int)source[i++];
                    if (c <= 0x7F)
                        dest[count++] = (byte)c;
                    else if (c > 0x7FF)
                    {
                        if ((count + 3) > maxDestBytes)
                            break;
                        dest[count++] = (byte)(0xE0 | (c >> 12));
                        dest[count++] = (byte)(0x80 | ((c >> 6) & 0x3F));
                        dest[count++] = (byte)(0x80 | (c & 0x3F));
                    }
                    else
                    {
                        //  0x7F < source[i] <= 0x7FF
                        if ((count + 2) > maxDestBytes)
                            break;
                        dest[count++] = (byte)(0xC0 | (c >> 6));
                        dest[count++] = (byte)(0x80 | (c & 0x3F));
                    }
                }
                if (count >= maxDestBytes)
                    count = maxDestBytes - 1;
                dest[count] = (byte)(0);
            }
            else
            {
                while (i < sourceChars)
                {
                    c = (int)(source[i++]);
                    if (c > 0x7F)
                    {
                        if (c > 0x7FF)
                            count++;
                        count++;
                    }
                    count++;
                }
            }
            result = count + 1;
            return result;
        }
        public static int UTF8ToUnicode(char[] dest, int maxDestChars, byte[] source, int sourceBytes)
        {
            int i, count;
            int c, result;
            int wc;

            if (source == null)
            {
                result = 0;
                return result;
            }
            result = (int)(-1);
            count = 0;
            i = 0;
            if (dest != null)
            {
                while ((i < sourceBytes) && (count < maxDestChars))
                {
                    wc = (int)(source[i++]);
                    if ((wc & 0x80) != 0)
                    {
                        if (i >= sourceBytes)
                            return result;
                        wc = wc & 0x3F;
                        if ((wc & 0x20) != 0)
                        {
                            c = (byte)(source[i++]);
                            if ((c & 0xC0) != 0x80)
                                return result;
                            if (i >= sourceBytes)
                                return result;
                            wc = (wc << 6) | (c & 0x3F);
                        }
                        c = (byte)(source[i++]);
                        if ((c & 0xC0) != 0x80)
                            return result;
                        dest[count] = (char)((wc << 6) | (c & 0x3F));
                    }
                    else
                        dest[count] = (char)wc;
                    count++;
                }
                if (count > maxDestChars)
                    count = maxDestChars - 1;
                dest[count] = (char)(0);
            }
            else
            {
                while (i < sourceBytes)
                {
                    c = (byte)(source[i++]);
                    if ((c & 0x80) != 0)
                    {
                        if (i >= sourceBytes)
                            return result;
                        c = c & 0x3F;
                        if ((c & 0x20) != 0)
                        {
                            c = (byte)(source[i++]);
                            if ((c & 0xC0) != 0x80)
                                return result;
                            if (i >= sourceBytes)
                                return result;
                        }
                        c = (byte)(source[i++]);
                        if ((c & 0xC0) != 0x80)
                            return result;
                    }
                    count++;
                }
            }
            result = count + 1;
            return result;
        }
        public static byte[] UTF8Encode(string ws)
        {
            int l;
            byte[] temp, result;

            result = null;
            if ((ws != null && ws.Length == 0))
                return result;
            temp = new byte[ws.Length * 3];
            l = UnicodeToUTF8(temp, temp.Length + 1, ws, ws.Length);
            if (l > 0)
            {
                result = new byte[l - 1];
                Array.Copy(temp, 0, result, 0, l - 1);
            }
            else
            {
                result = new byte[ws.Length];
                for (int i = 0; i < result.Length; i++)
                    result[i] = (byte)(ws[i]);
            }
            return result;
        }
        public static string UTF8Decode(byte[] s)
        {
            int l;
            char[] temp;
            string result;

            result = string.Empty;
            if (s == null)
                return result;
            temp = new char[s.Length + 1];
            l = UTF8ToUnicode(temp, temp.Length, s, s.Length);
            if (l > 0)
            {
                result = "";
                for (int i = 0; i < l - 1; i++)
                    result += temp[i];
            }
            else
            {
                result = "";
                for (int i = 0; i < s.Length; i++)
                    result += (char)(s[i]);
            }
            return result;
        }
        public static string UnicodeToKoDau(string s)
        {
            string retVal = string.Empty;
            char c;
            if (s == null)
                return retVal;
            int pos;
            char[] ch = s.ToCharArray();
            for (int i = 0; i < ch.Length; i++)
            {
                c = ch[i];
                if (c < 768 || c > 803)
                {
                    pos = uniChars.IndexOf(c);
                    if (pos >= 0)
                        retVal += KoDauChars[pos];
                    else
                        retVal += s[i];
                }
            }
            return retVal;
        }
       
        public static string UnicodeToWindows1252(string s)
        {
            string retVal = string.Empty;
            for (int i = 0; i < s.Length; i++)
            {
                int ord = (int)s[i];
                if (ord > 191)
                    retVal += "&#" + ord.ToString() + ";";
                else
                    retVal += s[i];
            }
            return retVal;
        }
        public static string UnicodeToKoDauForUrl(string s)
        {
            string retVal = string.Empty;
            if (s == null)
                return retVal;
            int pos;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i].ToString() != " ")
                {
                    pos = uniChars.IndexOf(s[i].ToString());
                    if (pos >= 0)
                        retVal += KoDauChars[pos];
                    else
                        retVal += s[i];
                }
                else
                {
                    retVal += "-";
                }
            }
            return retVal;
        }
        public static string UnicodeToISO8859(string src)
        {
            Encoding iso = Encoding.GetEncoding("iso8859-1");
            Encoding unicode = Encoding.UTF8;
            byte[] unicodeBytes = unicode.GetBytes(src);
            return iso.GetString(unicodeBytes);
        }
        public static string ISO8859ToUnicode(string src)
        {
            Encoding iso = Encoding.GetEncoding("iso8859-1");
            Encoding unicode = Encoding.UTF8;
            byte[] isoBytes = iso.GetBytes(src);
            return unicode.GetString(isoBytes);
        }
    }
}
